package com.zhi.service.impl;

import com.zhi.dao.StudentRepository;
import com.zhi.entity.Student;
import com.zhi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class StudentServiceImpl implements StudentService {
	
	@Autowired
	private StudentRepository studentRepository;

	@Override
	public List<Student> getEntityList() {
		return studentRepository.findAll();
	}
	
	@Override
	public List<Object[]> getEntityListWithCodeName() {
		return studentRepository.getEntityListWithCodeName();
	}
	

	@Override
	public Page<Student> getEntityListWithCodeName(Pageable pageable) {
		return studentRepository.getEntityListWithCodeName(pageable);
	}

	@Override
	public Page<Student> getEntityListWithCodeName(Pageable pageable,List<String> gradeIds) {
		return studentRepository.getEntityListWithCodeName(pageable,gradeIds);
	}

	@Override
	public Student getOne(String id) {
		return studentRepository.getOne(id);
	}
	
	@Override
	public List<Student> findAll(Student student) {
		Example<Student> example =Example.of(student);
		return studentRepository.findAll(example);
	}

	@Override
	public void save(Student Student) {
		studentRepository.save(Student);
	}

	@Override
	public void edit(Student Student) {
		studentRepository.save(Student);
		
	}

	@Override
	public void delete(String id) {
		studentRepository.deleteById(id);
	}

	@Override
	public Integer count(Student Student) {
		Example<Student> example =Example.of(Student);
		return (int)studentRepository.count(example);
	}

}
